﻿using System;

namespace Rsdn.Janus
{
    /// <summary>
    ///   OutboxDummyForm - control for manage outgoing messages/rates.
    /// </summary>
    public sealed partial class OutboxDummyForm : OutboxDummyFormBase
    {
        #region Constructor(s) & Dispose

        /// <summary>
        ///   Initializes a new instance of the <see cref = "OutboxDummyForm" /> class.
        /// </summary>
        /// <param name = "provider">The provider.</param>
        /// <param name = "manager">The manager.</param>
        /// <exception cref = "ArgumentNullException"><paramref name = "provider" /> is <c>null</c>.</exception>
        public OutboxDummyForm(IServiceProvider provider, OutboxManagerBase manager) 
            : base(provider, manager)
        {
            InitializeComponent();
            MessageForm.MessageSent += MessageSent;
        }

        #endregion

        #region Private Methods

        private void MessageSent(object sender, int mid)
        {
            if (Visible)
            {
                RefreshList();
            }

// Удаляем делегат чтобы позволить GC убрать форму, иначе так и будет висеть в памяти
            // ((WriteMessageForm) sender).OnSendMessage -= new SendMessageHandler(MessageSent);
        }

        #endregion

        /// <summary>
        /// Activates the view.
        /// </summary>
        public override void ActivateView()
        {
            MessageForm.MessageSent += MessageSent;
        }

        /// <summary>
        /// Deactivates the view.
        /// </summary>
        public override void DeactivateView()
        {
            MessageForm.MessageSent -= MessageSent;
        }
    }
}